// =============================================================
// CFactory/CService/CServiceProxy/CServiceContainer
// ---------------------------------------
// Author : Woo-Hyun Kim
// Email : woorung@icu.ac.kr or woorung@nhncorp.com
// Date : Aug. 24, 2007
//
// # This is based on one of gSOAP examples, varparam and mtom
// =============================================================

namespace base { // begin of namespace


//gsoap cube service name:        CFactory
//gsoap cube service style:       rpc
//gsoap cube service encoding:    encoded
//gsoap cube service namespace:   urn:CService
//gsoap cube service location:    http://localhost:10088/cgi-bin/service.cgi

class cube__CObject {
public:
	struct soap *soap;

	cube__CObject();
	//cube__CObject(const cube__CObject &rhs);
	virtual ~cube__CObject();

	//virtual cube__CObject *clone() const;
	//virtual cube__CObject &operator=(const cube__CObject &rhs);
};

class cube__CMessage : public cube__CObject {
public:
	char *message;

	cube__CMessage();
	//cube__CMessage(const cube__CMessage &rhs);
	virtual ~cube__CMessage();

	//virtual cube__CMessage *clone() const;
	//virtual cube__CMessage &operator=(const cube__CMessage &rhs);

	int set(char *msg);
	char *get();

	void print();
};

class cube__CKeyValue : public cube__CObject {
public:
	char *key;
	char *value;

	cube__CKeyValue();
	virtual ~cube__CKeyValue();

	void set(char *k, char *v);
	char *getKey();
	char *getValue();
	void setKey(char *k);
	void setValue(char *v);

	void print();
};

class cube__CServiceInfo : public cube__CObject {
public:
	char *name;

	// node agent status
	char *ip;
	int port;
	time_t ttl; // by the second

	// node status
	float cpu;
	float load;

	cube__CServiceInfo();
	cube__CServiceInfo(char *__name, char *__ip, int __port, time_t __ttl);
	virtual ~cube__CServiceInfo();

	void set(char *name, char *ip, int port, time_t ttl);
	void setName(char *name);
	void setStatus(float cpu, float load);

	char *getName();
	float getCPU();
	float getLoad();
	char *getIP();
	int getPort();
	time_t getTTL();
};

class cube__CService : public cube__CObject {
public:
	char *name;
	char *iname; // instance name for uniqueness

	cube__CService();
	cube__CService(char *__name);
	cube__CService(char *__name, char *__iname);
	virtual ~cube__CService();

	void set(char *name);
	void set(char *name, char *iname);

	void service(char *name);
	char *service();

	void instance(char *iname);
	char *instance();
};

/*
class cube__CTask : public cube__CObject {
public:
	char *_command;
	int work_place;

	cube__CTask();
	virtual ~cube__CTask();

	void command(char *cmd);
	void workplace(int wplace);
	
	char *command();
	int workplace();
};
*/

// for using dynamic array
class CObjectArray : public cube__CObject {
public:
	cube__CObject **__ptr;
	int __size;
	int __offset;
	
	CObjectArray();
	CObjectArray(int n);
	virtual ~CObjectArray();

	void grow(int n);

	virtual cube__CObject *&operator[](int i);
};

//---------------------------------------------------------------------------
// service invocation
//---------------------------------------------------------------------------
struct cube__invokeResponse {
	cube__CObject *out;
};

int cube__initialize(cube__CService *serviceid, int &res);
int cube__invoke(cube__CService *serviceid, cube__CObject *in, struct cube__invokeResponse &res);
int cube__finalize(cube__CService *serviceid, int &res);
//---------------------------------------------------------------------------






//---------------------------------------------------------------------------
// file transfer
//---------------------------------------------------------------------------
#import "soap12.h"
#import "xop.h"
#import "xmlmime.h"

//gsoap cubex schema type-documentation: Data holds a MIME attachment
struct cubex__Data
{
	_xop__Include xop__Include;
	@char *xmlmime__contentType; // set as attribute type, not element
};

//gsoap cubex schema type-documentation: DataSet holds a set of MIME attachments
struct cubex__DataSet
{
	int __size;
	struct cubex__Data *item;
};

//gsoap cubex schema type-documentation: Keys holds a set of strings to access the data collection at the server side
struct cubex__Keys
{
	int __size;
	char **key;
	char *repository;
};

//gsoap cubex schema type-documentation: put data response
struct cubex__putResponse {
	struct cubex__Keys __keys;
};

//gsoap cubex schema type-documentation: get data response
struct cubex__getResponse {
	struct cubex__DataSet __data;
};

//gsoap cube service method-mime-type: PutData */*
//gsoap cube service method-documentation: PutData stores a data set at the server side and returns a set of unique keys to access that data
int cube__put(struct cubex__DataSet *__data, struct cubex__putResponse *key);

//gsoap cube service method-mime-type: GetData */*
//gsoap cube service method-documentation: GetData gets a set of data items from the server given a set of keys
int cube__get(struct cubex__Keys *__keys, struct cubex__getResponse *data);


} // end of namespace
